package com.baidu.music;

import com.baidu.music.IMediaPlaybackService;
import com.baidu.music.R;
import com.baidu.utils.Logger;
import com.baidu.utils.MusicUtils;

import android.app.Activity;
import android.content.ComponentName;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.os.IBinder;
public class BaiduMusicActivity extends Activity implements OnClickListener {
	private IMediaPlaybackService mService = null;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        View homeButton = findViewById(R.id.menu_home);
        homeButton.setOnClickListener(this);
        View listButton = findViewById(R.id.menu_list);
        listButton.setOnClickListener(this);
        View moreButton = findViewById(R.id.menu_more);
        moreButton.setOnClickListener(this);
         MusicUtils.bindToService(this, osc);
    }

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
			case R.id.menu_home:
				Logger.i("play..");
			try {
				mService.play();
			} catch (RemoteException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			break;
			case R.id.menu_list:
			try {
				Logger.i("pause..");
				mService.pause();
			} catch (RemoteException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			break;
			case R.id.menu_more:
				//mService.setRepeatMode()
			break;
		}
		
	}
	   private ServiceConnection osc = new ServiceConnection() {
           public void onServiceConnected(ComponentName classname, IBinder obj) {
               mService = IMediaPlaybackService.Stub.asInterface(obj);

           }
           public void onServiceDisconnected(ComponentName classname) {
               mService = null;
           }
   };
	
}